<template>
  <div class="Tables">
    <el-table :data="tableData" border style="width: 100%" row-key="id" >
      <el-table-column prop="title" label="模板标题 " align="center">   </el-table-column>
      <el-table-column prop="content" label="模板内容 " align="center" width="800">
        <template slot-scope="scope">
           <el-tooltip class="item" effect="dark" placement="top">
            <div slot="content" class="zzyqshowtag">
              <span

              >
                {{ scope.row.content }}
              </span>
            </div>
            <span class="ellipsis">{{ scope.row.content}}</span>
          </el-tooltip>
        </template>
      </el-table-column>
      <el-table-column prop="create_user" label="添加人 " align="center">   </el-table-column>
      <el-table-column prop="update_time" label="更新时间 " align="center">   </el-table-column>
      <el-table-column prop="status" label="是否启用 " align="center" >
        <template slot-scope="scope">
          <el-switch v-model="scope.row.status" :disabled="!checkPermission(['commentTemplateUsed'])"  @change="changeis_hot(scope.row.status,scope.row.id)" :active-value='1' :inactive-value='0'></el-switch>
        </template>
      </el-table-column>
      <el-table-column prop="" label="操作" align="center" v-if="checkPermission(['commentTemplateUpdate','commentTemplateDelete'])">
        <template slot-scope="scope">
          <span class="edittext" v-if="checkPermission(['commentTemplateUpdate'])" @click="editform(scope.row.id)">修改</span>
          <span class="edittext" v-if="checkPermission(['commentTemplateDelete'])" @click="deleteform(scope.row.id)">删除</span>
        </template>
      </el-table-column>
    </el-table>
    <el-row>
      <el-col :span="24" class="pagination">
        <!-- 翻页 -->
        <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="pages.page"
          :page-sizes="[10, 20, 30]" :page-size="10" background layout="total, sizes, prev, pager, next" :total="pages.total">
        </el-pagination>
      </el-col>
    </el-row>
  </div>
</template>

<script>
  import {
    updateStateData,
    updatesort,
    updateIsHot,
    commentupdateStatus,
    commenttemplatedelete
  } from '@/api/course'
  //按钮权限验证
  import checkPermission from "@/utils/permission";
  export default {
    data() {
      return {
        //表格数据
        tableData: [],
        //页码数据
        pages: {},
        value: true
      }
    },
    props: {
      //表格数据
      tabData: {
        type: Object,
        default: () => {
          return {}
        },
      },
    },
    watch: {
      tabData(val) {
        this.tableData = val.list
        this.pages = val.page

      },
    },
    methods: {

      //按钮权限验证
      checkPermission,
      //修改状态
      async changeis_hot(val, id) {
        let state = val ? 0 : 1
        let params = {
          id,
          status: state
        }
        let data = await commentupdateStatus(params)
        if (data.code == '0000') {
          this.$message.success('修改状态成功！')
          //刷新列表
          this.$emit('refreshdata')
        } else {
          //刷新列表
          this.$emit('refreshdata')
        }
      },

      //审核状态 提示
      renderTip(h, {
        column
      }) {
        return h(
          'div', {
            style: 'display:flex;margin:0 auto; justify-content: center;',
          },
          [
            h('span', column.label),
            h('promptmessage', {
              props: {
                messages: ['提交的审核信息将在审核通过后才可同步展示'],
              },
            }),
          ]
        )
      },


      handleSizeChange(val) {
        this.$emit('changepageTotal', val)
      },
      handleCurrentChange(val) {
        this.$emit('changepage', val)
      },
      //编辑
      editform(id) {
        let params = {
          id,
        }
        //显示dialog通知父组件打开弹窗
        this.$emit('openedit', params)
      },
      //删除
      async deleteform(id){

        let data=await commenttemplatedelete({id:id})
        if(data.code=='0000'){
           this.$message.success('删除成功！')
            this.$emit('deleteform')
        }
      }
    },
  }
</script>

<style scoped lang='scss'>
  .Tables {
    margin-top: 25px;
  }

  .edittext {
    margin: 0 10px;
    color: #4c68ef;
    cursor: pointer;
  }

  .pagination {
    margin-top: 10px;
    display: flex;
    justify-content: flex-end;
  }

  ::v-deep {
    .el-input--mini .el-input__inner {
      text-align: center;
    }
  }

  .sortbtn {
    padding: 5px 8px;
  }
</style>
